package com.wenhao.interview.huawei;

import javax.lang.model.type.TypeMirror;
import java.util.Currency;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author Wenhao Tong
 * @create 2021-07-21 18:46
 */
public class Main1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int N = scanner.nextInt();
            int K = scanner.nextInt();
            Map<Integer,Integer> map = new HashMap<>();
            int max = 0;
            for (int i = 0;i < K;i++) {
                int time = scanner.nextInt();
                int start = scanner.nextInt();
                int end = scanner.nextInt();
                if (start == end) {
                    continue;
                }
                int timeStep;
                if (end - start > N / 2) {
                    timeStep = N - end + start;
                } else {
                    timeStep = end - start;
                }
                timeStep *= 5;
                for (int j = time;j < time + timeStep;j++) {
                    if (map.containsKey(j)) {
                        int temp = map.get(j) + 1;
                        map.put(j,temp);
                        max = max > temp ? max : temp;
                    } else {
                        map.put(j,1);
                        max = max > 1 ? max : 1;
                    }
                }
            }
            System.out.println(max);
        }
    }
}
